package redis

import (
	"dc-news/common/global/setting"
	"fmt"
	"github.com/go-redis/redis"
	"go.uber.org/zap"
)

var Client *redis.Client

func InitRedis() (err error) {
	Client = redis.NewClient(&redis.Options{
		Addr:     fmt.Sprintf("%s:%s", setting.Conf.RedisHost, setting.Conf.RedisPort),
		Password: "", // no password set
		DB:       0,  // use default DB
	})
	_, err = Client.Ping().Result()
	if err != nil {
		zap.S().Error(err)
		return
	}
	return err
}
